//
//  UserInfo.m
//  ZzzzyManProject
//
//  Created by mac on 16/3/5.
//  Copyright © 2016年 ZzzzyMan@. All rights reserved.
//

#import "UserInfo.h"
@interface UserInfo() <NSCoding>
@end

@implementation UserInfo

+ (instancetype) userInfoWithDict:(NSDictionary *)dict {
    UserInfo * userInfo = [[UserInfo alloc] init];
    [userInfo setValuesForKeysWithDictionary:dict];
    return userInfo;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

#pragma mark - 保存对象
- (void)savaUserInfo {
    NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"userInfo.plist"];
    [NSKeyedArchiver archiveRootObject:self toFile:path];
    NSLog(@"%@",path);
}

#pragma mark - 取出对象
+ (instancetype)loadUserInfo {
    NSString * path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:@"userInfo.plist"];
    UserInfo * userInfo = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
    return userInfo;
}

#pragma mark - 归档
- (void)encodeWithCoder:(NSCoder *)aCoder {
    [aCoder encodeObject:self.name forKey:@"name"];
    [aCoder encodeObject:self.userName forKey:@"userName"];
    [aCoder encodeObject:self.passWord forKey:@"passWord"];
    [aCoder encodeObject:self.iconUrl forKey:@"iconUrl"];
    [aCoder encodeObject:self.isPush forKey:@"isPush"];
}

#pragma mark - 反归档
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    UserInfo * info = [[UserInfo alloc] init];
    info.name = [aDecoder decodeObjectForKey:@"name"];
    info.userName = [aDecoder decodeObjectForKey:@"userName"];
    info.passWord = [aDecoder decodeObjectForKey:@"passWord"];
    info.iconUrl = [aDecoder decodeObjectForKey:@"iconUrl"];
    info.isPush = [aDecoder decodeObjectForKey:@"isPush"];
    return info;
}


- (NSString *)description {
    return [NSString stringWithFormat:@"name:%@ ,userName:%@ ,passWord:%@ ,iconUrl:%@",self.name,self.userName,self.passWord,self.iconUrl];
}

@end
